#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2505;

int n, m;
vector<int> ch[N];
int s[N], p[N], f[N];
ll v[N];
ll dp[N][N];
int sz[N];
void dfs(int u) {
  rep(j, 1, m + 1) dp[u][j] = -1e18;
  sz[u] = 1;
  dp[u][1] = v[u];
  for (int v : ch[u]) {
    dfs(v);
    per(i, min(m + 1, sz[u] + sz[v]), 2) {
      int mn = i - sz[u], mx = i - 1;
      rep(j, max(1, mn), min(sz[v], mx)) {
        dp[u][i] = max(dp[u][i], dp[u][i - j] + dp[v][j]);
      }
    }
    sz[u] += sz[v];
  }
}
bool check(int x) {
  rep(i, 1, n) v[i] = 100000 * p[i] - 1ll * x * s[i];
  dfs(0);
  return dp[0][m + 1] >= 0;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> m >> n;
  rep(i, 1, n) cin >> s[i] >> p[i] >> f[i];
  rep(i, 1, n) ch[f[i]].push_back(i);

  int l = 1, r = 1e9;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      l = mid + 1;
    else
      r = mid - 1;
  }
  cout << fixed << setprecision(3) << r / 100000.0;
  return 0;
}